package idv.takeshi.software.productline.bookstore.domain.model.order;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * A model class as a payment to indicate that it shall be paid by credit card.
 * @author takeshi
 *
 */
@Entity
@Table(name = "CREDIT_CARD")
public class CreditCard extends BeforeDeliveryPayment {
	
	@Column(length = 30, name = "CC_PAYER_NAME")
	private String payerName;
	@Column(length = 16, name = "CREDIT_CARD_NO") 
	private String creditCardNumber;
	@Column(length = 2, name = "VALID_MONTH") 
	private String validMonth;
	@Column(length = 2, name = "VALID_YEAR") 
	private String validYear;
	@Column(length = 3, name = "SECURITY_CODE") 
	private String securityCode;
	@Column(length = 20)
	@Enumerated(EnumType.STRING)
	private CreditCardType creditCardType;


	/**
	 * @return the payerName
	 */
	public String getPayerName() {
		return payerName;
	}

	/**
	 * @param payerName the payerName to set
	 */
	public void setPayerName(String payerName) {
		this.payerName = payerName;
	}

	/**
	 * @return the creditCardNumber
	 */
	public String getCreditCardNumber() {
		return creditCardNumber;
	}

	/**
	 * @param creditCardNumber the creditCardNumber to set
	 */
	public void setCreditCardNumber(String creditCardNumber) {
		this.creditCardNumber = creditCardNumber;
	}

	/**
	 * @return the validMonth
	 */
	public String getValidMonth() {
		return validMonth;
	}

	/**
	 * @param validMonth the validMonth to set
	 */
	public void setValidMonth(String validMonth) {
		this.validMonth = validMonth;
	}

	/**
	 * @return the validYear
	 */
	public String getValidYear() {
		return validYear;
	}

	/**
	 * @param validYear the validYear to set
	 */
	public void setValidYear(String validYear) {
		this.validYear = validYear;
	}

	/**
	 * @return the securityCode
	 */
	public String getSecurityCode() {
		return securityCode;
	}

	/**
	 * @param securityCode the securityCode to set
	 */
	public void setSecurityCode(String securityCode) {
		this.securityCode = securityCode;
	}

	/**
	 * @return the creditCardType
	 */
	public CreditCardType getCreditCardType() {
		return creditCardType;
	}

	/**
	 * @param creditCardType the creditCardType to set
	 */
	public void setCreditCardType(CreditCardType creditCardType) {
		this.creditCardType = creditCardType;
	}

	/* (non-Javadoc)
	 * @see idv.takeshi.software.productline.bookstore.domain.model.order.Payment#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj == null) { return false; }
		   if (obj == this) { return true; }
		   if (!(obj instanceof CreditCard)) {
		     return false;
		   }
		   CreditCard rhs = (CreditCard) obj;
		   return new EqualsBuilder()
		   	   .appendSuper(super.equals(rhs))
			   .append(this.payerName, rhs.payerName)
			   .append(this.creditCardNumber, rhs.creditCardNumber)
			   .append(this.validMonth, rhs.validMonth)
			   .append(this.validYear, rhs.validYear)
			   .append(this.securityCode, rhs.securityCode)
			   .append(this.creditCardType, rhs.creditCardType)
		       .isEquals();
	}

	/* (non-Javadoc)
	 * @see idv.takeshi.software.productline.bookstore.domain.model.order.Payment#hashCode()
	 */
	@Override
	public int hashCode() {
		return new HashCodeBuilder(19, 97).
		   appendSuper(super.hashCode()).
	       append(this.payerName).
	       append(this.creditCardNumber).
	       append(this.validMonth).
	       append(this.validYear).
	       append(this.securityCode).
	       append(this.creditCardType).
	       toHashCode();
	}
}
 
